home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / DrawSprocket / GoggleSprocket / GoggleSprocketTest Sources / GSpTest_Main.cp < prev    next >
Encoding:
Text File  |  1998-03-12  |  3.5 KB  |  164 lines  |  [TEXT/CWIE]

  1. /*
  2. ********************************************************************************
  3. **
  4. ** File: GSpTest_Main.cp
  5. **
  6. ** Description:
  7. **
  8. **    Contains the program entry point and some error handling routines.
  9. **
  10. ********************************************************************************
  11. */
  12. #include "GSpTest_Main.h"
  13. #include "GSpTest_Init.h"
  14. #include "GSpTest_EventLoop.h"
  15.  
  16. #include "GoggleSprocket.h"
  17. #include "GoggleSprocketDevices.h"
  18.  
  19. /*
  20. ********************************************************************************
  21. ** local constants
  22. ********************************************************************************
  23. */
  24. #define kErrorDialogItem_Button            1
  25. #define kErrorDialogItem_UserFrame        6
  26.  
  27. #define kDLOG_ErrorID        128
  28.  
  29. /*
  30. ********************************************************************************
  31. ** prototypes
  32. ********************************************************************************
  33. */
  34. static void DoTest( void );
  35.  
  36. /*
  37. ********************************************************************************
  38. **
  39. ** Name: main
  40. **
  41. ** Description:
  42. **
  43. **    Program entry point.
  44. **
  45. ********************************************************************************
  46. */
  47. void main( void )
  48. {
  49.     OSErr theError;
  50.         
  51.     // increase size of the app heap zone to its maximum
  52.     MaxApplZone();
  53.     
  54.     // alloc the master pointers
  55.     for (int i = 0; i < 5; i++)
  56.         MoreMasters();
  57.     
  58.     // initialization
  59.     theError = Initialize();
  60.     if( theError )
  61.         HandleError( theError, true );
  62.     
  63.     // Testing
  64.     DoTest();
  65.     
  66.     // main loop
  67.     EventLoop();
  68.     
  69.     // termination
  70.     Terminate();
  71. }
  72.  
  73. /*
  74. ********************************************************************************
  75. **
  76. ** Name: HandleError
  77. **
  78. ** Description:
  79. **
  80. **    Displays an error dialog and terminates the program if the error
  81. **    is fatal.
  82. **
  83. ********************************************************************************
  84. */
  85. void HandleError(
  86.     short inTextID,        // 'STR ' id of error text
  87.     Boolean inFatal        // true if error is fatal
  88. )
  89. {
  90.     GrafPtr                theOldPort;
  91.     DialogPtr            theDialog;
  92.  
  93.     theDialog = GetNewDialog( kDLOG_ErrorID, nil, (WindowPtr) -1);
  94.     if (theDialog != nil) 
  95.     {
  96.         Handle theItem;
  97.         short theItemType;
  98.         Rect theItemRect;
  99.         StringHandle theString;
  100.         short theItemHit;
  101.  
  102.         SysBeep( 30 );
  103.         SetCursor( &qd.arrow );
  104.         
  105.         GetPort( &theOldPort );
  106.         SetPort( theDialog );
  107.         
  108.         // frame user area
  109.         PenPat( &qd.gray );
  110.         GetDialogItem( theDialog, kErrorDialogItem_UserFrame, &theItemType, &theItem,
  111.             &theItemRect );
  112.         FrameRect( &theItemRect );
  113.         PenPat( normal );
  114.         
  115.         // get the button item
  116.         GetDialogItem( theDialog, kErrorDialogItem_Button, &theItemType, &theItem,
  117.             &theItemRect );
  118.         SetDialogDefaultItem( theDialog, kErrorDialogItem_Button );
  119.  
  120.         // display the error message        
  121.         theString = GetString( inTextID );
  122.         if( NULL == theString )
  123.             theString = GetString( kError_Unknown );
  124.         HLock( (Handle)theString );
  125.         ParamText( *theString, nil, nil, nil );
  126.         HUnlock( (Handle)theString );
  127.  
  128.         // show the dialog        
  129.         ShowWindow( theDialog );
  130.         ModalDialog( nil, &theItemHit );
  131.  
  132.         // restore things        
  133.         SetPort( theOldPort );
  134.         DisposeWindow( theDialog );
  135.     }
  136.     else
  137.         Terminate();
  138.     
  139.     // fatal?
  140.     if ( inFatal )
  141.         Terminate();
  142.     
  143. }
  144.  
  145. /*
  146. ********************************************************************************
  147. **
  148. ** Name: DoTest
  149. **
  150. ** Description:
  151. **
  152. **    Does GSp Testing.
  153. **
  154. ********************************************************************************
  155. */
  156. void DoTest( void )
  157. {
  158.     OSStatus theError;
  159.     
  160.     // test device selection dialog
  161.     theError = GSpConfigure( NULL, NULL );
  162.     if( theError )
  163.         return;
  164. }